#include "BlockQueue.hpp"
#include <pthread.h>

#include <iostream>
#include <unistd.h>
// char buffer[128] = {0};
//std::string buffer(128, '0');
static int cnt = 100;
void *product(void * ptr)
{
    MyBqueue::BlockQueue<std::string>* p = (MyBqueue::BlockQueue<std::string>*)ptr;
    while(cnt--)
    {
        p->push(std::to_string(cnt));
        usleep(50000);

    }
    return nullptr;
}

void *consumer(void * ptr)
{
    MyBqueue::BlockQueue<std::string>* p = (MyBqueue::BlockQueue<std::string>*)ptr;
    std::string tmp;
    while(true)
    {
        tmp = p->pop();
        std::cout<<gettid()<<":"<<tmp<<std::endl;
        usleep(10000);
    }
    return nullptr;
}
int main()
{

    MyBqueue::BlockQueue<std::string>* ptr = new MyBqueue::BlockQueue<std::string>(20);
    pthread_t c1,c2,c3;
    pthread_t c4,c5,c6;


    pthread_create(&c1, nullptr, product, ptr);
     //pthread_create(&c2, nullptr, product, nullptr);
    // pthread_create(&c3, nullptr, product, nullptr);

    pthread_create(&c4, nullptr, consumer, ptr);
    pthread_create(&c5, nullptr, consumer, ptr);
    pthread_create(&c6, nullptr, consumer, ptr);

    pthread_join(c1, nullptr);
    pthread_join(c2, nullptr);
    pthread_join(c3, nullptr);
    pthread_join(c4, nullptr);
    pthread_join(c5, nullptr);



    return 0;
}